import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { RequestHeaderEnum } from "/@/enums/httpEnum"

export enum Url {
  mchNotifyExport = "/pay-service/config/exportXls",
  mchNotifyImport = "/pay-service/config/exportXls",
  payOrderExport = "/pay-service/config/exportXls",
  payOrderImport = "/pay-service/config/importExcel",
  refundOrderExport = "/pay-service/config/exportXls",
  refundOrderImport = "/pay-service/config/importExcel",
  transOrderExport = "/pay-service/config/exportXls",
  transOrderImport = "/pay-service/config/importExcel",
}

// ======================================================
// 转账
// ======================================================
export const pageTransferOrder = (params) => {
  return defHttp.get({ url: "/pay-service/transfer/pageTransferOrder", params })
}
export const getTransferOrder = (params) => {
  return defHttp.get({ url: "/pay-service/admin/transfer/getTransferOrder", params })
}

// ======================================================
// 退款订单
// ======================================================
export const pageRefundOrder = (params) => {
  return defHttp.get({ url: "/pay-service/admin/refund/page", params })
}

export const getRefundOrder = (params) => {
  return defHttp.get({ url: "/pay-service/admin/refund/getById", params })
}

export const doRefund = (params) => {
  return defHttp.post({ url: "/pay-service/admin/refund/refundOrder", params })
}

// ======================================================
// 支付方式
// ======================================================
export const listPayWay = (params) => {
  return defHttp.get({ url: "/pay-service/mgr/payWay/page", params })
}

export const listAllPayWay = () => {
  return defHttp.get({ url: "/pay-service/mgr/payWay/listPayWay", params: {} })
}

export const getPayWay = (params) => {
  return defHttp.get({ url: "/pay-service/mgr/payWay/getByWayCode", params })
}

export const deletePayWay = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mgr/payWay/deleteByWayCode", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const savePayWay = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mgr/payWay/update" : "/pay-service/mgr/payWay/save"
  return defHttp.post({ url: url, params })
}

// ======================================================
// 支付订单
// ======================================================
export const listPayOrder = (params) => {
  const headers = {}
  headers[RequestHeaderEnum.TENANT_ID] = params.tenantId
  return defHttp.get({ url: "/pay-service/admin/payOrder/pageOrder", params })
}

export const getPayOrder = (params) => {
  return defHttp.get({ url: "/pay-service/admin/payOrder/getByOrderNo", params })
}

export const getTradeData = (params) => {
  return defHttp.get({ url: "/pay-service/admin/trade/getTradeData", params })
}

export const closeOrder = (params) => {
  return defHttp.post({ url: "/pay-service/admin/payOrder/closeOrder", params })
}

export const continuePay = (params) => {
  return defHttp.post({ url: "/pay-service/admin/payOrder/continuePay", params })
}

export const listPayNode = (params) => {
  return defHttp.get({ url: "/pay-service/payNode/listPayNode", params }, { joinParamsToUrl: true })
}

// ======================================================
// 支付接口定义
// ======================================================
export const listPayIfDefine = (params) => {
  return defHttp.get({ url: "/pay-service/mgr/payIfDefine/page", params })
}

export const listAllPayIfDefine = (params) => {
  return defHttp.get({ url: "/pay-service/mgr/payIfDefine/list", params })
}

export const getByIfCode = (params) => {
  return defHttp.get({ url: "/pay-service/mgr/payIfDefine/getByIfCode", params })
}

export const deletePayIfDefine = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mgr/payIfDefine/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeletePayIfDefine = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/mchInfo/deleteBatch", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const saveOrUpdatePayIfDefine = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mgr/payIfDefine/update" : "/pay-service/mgr/payIfDefine/save"
  return defHttp.post({ url: url, params })
}

export const listMchNotify = (params) => {
  return defHttp.get({ url: "/pay-service/mchNotify/page", params })
}

export const listMchInfo = (params) => {
  return defHttp.get({ url: "/pay-service/mchInfo/page", params })
}
export const getMchInfo = (params) => {
  return defHttp.get({ url: "/pay-service/mchInfo/getByMchNo", params })
}

export const deleteMchInfo = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mchInfo/deleteById", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteMchInfo = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/mchInfo/deleteBatch", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const saveOrUpdateMch = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mchInfo/update" : "/pay-service/mchInfo/save"
  return defHttp.post({ url: url, params })
}

export const listCanRelatedPassage = (params) => {
  return defHttp.get({ url: "/pay-service/mch/payPassage/listCanRelated", params })
}

export const updatePassageStatus = (params) => {
  return defHttp.put({ url: "/pay-service/mch/payPassage/updateStatus", params }, { joinParamsToUrl: true })
}

export const getCheckBatch = (params) => {
  return defHttp.get({ url: "/pay-service/checkBatch/get", params })
}

export const pageCheckBatch = (params) => {
  return defHttp.get({ url: "/pay-service/checkBatch/page", params })
}

/**
 * 重新对账
 */
export const refreshCheck = (params) => {
  return defHttp.put({ url: "/pay-service/checkBatch/refreshCheck", params }, { joinParamsToUrl: true })
}

export const deleteCheckBatch = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/checkBatch/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteCheckBatch = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/checkBatch/batchDelete", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const getChannelBill = (params) => {
  return defHttp.get({ url: "/pay-service/channelBill/get", params })
}

export const pageChannelBill = (params) => {
  return defHttp.get({ url: "/pay-service/channelBill/page", params })
}

export const getCheckDiff = (params) => {
  return defHttp.get({ url: "/pay-service/checkDiff/get", params })
}

export const pageCheckDiff = (params) => {
  return defHttp.get({ url: "/pay-service/checkDiff/page", params })
}

export const ignoreCheckDiff = (params) => {
  return defHttp.put({ url: "/pay-service/checkDiff/ignoreDiff", params }, { joinParamsToUrl: true })
}

export const batchDeleteCheckDiff = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/checkDiff/batchDelete", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const currentTenantBindApp = () => {
  return defHttp.post({ url: "/pay-service/mchApp/currentTenantBindApp", params: {} })
}

export const saveOrUpdateMchApp = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mchApp/update" : "/pay-service/mchApp/save"
  return defHttp.post({ url: url, params })
}

export const listAllMchApp = (params) => {
  return defHttp.get({ url: "/pay-service/mchApp/listAllMchApp", params })
}

export const listMchApp = (params) => {
  return defHttp.get({ url: "/pay-service/mchApp/page", params })
}

export const getMchApp = (params) => {
  return defHttp.get({ url: "/pay-service/mchApp/getById", params })
}

export const deleteMchApp = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mchApp/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteMchApp = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/mchApp/deleteBatch", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const listCashierConfig = (params) => {
  return defHttp.get({ url: "/pay-service/cashierConfig/list", params })
}

export const saveCashierConfig = (params, isUpdate) => {
  const api = isUpdate ? "/pay-service/cashierConfig/update" : "/pay-service/cashierConfig/save"
  return defHttp.post({ url: api, params }, { joinParamsToUrl: true })
}
export const deleteCashierConfig = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/cashierConfig/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const listPayPassage = (params) => {
  return defHttp.get({ url: "/pay-service/mch/payPassage/list", params })
}

export const getPayPassage = (params) => {
  return defHttp.get({ url: "/pay-service/mch/payPassage/get", params })
}

export const deletePayPassage = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mch/payPassage/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const saveOrUpdatePayPassage = (params) => {
  return defHttp.post({ url: "/pay-service/mch/payPassage/saveOrUpdate", params })
}

// ======================================================
// 商户码牌
// ======================================================
export const getMchQrcodeTemplate = (params) => {
  return defHttp.get({ url: "/pay-service/mchQrcode/template/get", params })
}

export const pageMchQrcodeTemplate = (params) => {
  return defHttp.get({ url: "/pay-service/mchQrcode/template/page", params })
}

export const listMchQrcodeTemplate = (params) => {
  return defHttp.get({ url: "/pay-service/mchQrcode/template/list", params })
}

export const saveOrUpdateMchQrcodeTemplate = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mchQrcode/template/update" : "/pay-service/mchQrcode/template/save"
  return defHttp.post({ url: url, params })
}

export const deleteMchQrcodeTemplate = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mchQrcode/template/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteMchQrcodeTemplate = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/mchQrcode/template/batchDelete", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const mchQrcodeBindMch = (params) => {
  return defHttp.post({ url: "/pay-service/mchQrcode/bindMch", params })
}

export const getMchQrcodeView = (params) => {
  return defHttp.post({ url: "/pay-service/mchQrcode/view", params })
}

export const getMchQrcode = (params) => {
  return defHttp.get({ url: "/pay-service/mchQrcode/get", params })
}

export const pageMchQrcode = (params) => {
  return defHttp.get({ url: "/pay-service/mchQrcode/page", params })
}

export const saveOrUpdateMchQrcode = (params, isUpdate) => {
  const url = isUpdate ? "/pay-service/mchQrcode/update" : "/pay-service/mchQrcode/save"
  return defHttp.post({ url: url, params })
}

export const deleteMchQrcode = (params, handleSuccess) => {
  return defHttp.delete({ url: "/pay-service/mchQrcode/delete", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteMchQrcode = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/pay-service/mchQrcode/batchDelete", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
